Skip to content

Introduce light node & refactor RPC client#681

Merged
tzdybal merged 24 commits intomainfrom
connor/wrap-subscribe
Jan 19, 2023
Merged

Introduce light node & refactor RPC client#681
tzdybal merged 24 commits intomainfrom
connor/wrap-subscribe

Conversation

@S1nus
Copy link
Copy Markdown
Contributor

@S1nus S1nus commented Jan 10, 2023

Overview

Goal is to refactor rpc/server.go/Server to accept the tendermint/rpc/client interface

Closes #662; Closes #663; Closes #664; Closes #682.

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

@S1nus
Copy link
Copy Markdown
Contributor Author

S1nus commented Jan 10, 2023

Is there a concern that this won't stop?

Copy link
Copy Markdown
Contributor

@tzdybal tzdybal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be cleaner to have following structure:

  • node:
    • node.go
    • full:
      • node.go, client.go, etc...
    • light:
      • node.go, client.go, etc...

Comment thread node/full.go
Comment thread rpc/server.go Outdated
Comment thread rpc/json/service.go Outdated
@S1nus S1nus marked this pull request as ready for review January 10, 2023 21:31
@S1nus S1nus requested a review from tzdybal January 10, 2023 21:31
@tzdybal tzdybal requested review from a team, Manav-Aggarwal and gupadhyaya and removed request for a team January 10, 2023 22:34
@gupadhyaya
Copy link
Copy Markdown
Contributor

@S1nus @tzdybal not sure why we need a separate package "full"? we could simply put them all under "node" package:

node
     - client.go
     - full.go
     - node.go (interface)
     - light.go
     - lightclient.go
     ...

will this not be sufficient? i would only make separate package if we expect repeated functionalities for full and light nodes. But then, we would end up duplicating lot of code.
in general, what services (functionalities) do we anticipate for light node?

@tzdybal
Copy link
Copy Markdown
Contributor

tzdybal commented Jan 11, 2023

I requested for introducing directories, because I felt like full_node.go and full_client.go + all tests files, will make a bit of a mess sooner than later.

For some context: #661

Both full and light nodes will implement simplified Node interface - which basically allows us to Start a node and create rpc.Client compatible with cosmos-sdk.
Client implementation returned by full node will be completely different than the one returned by light node. I don't expect to share a lot of code between light and full nodes & clients.

@gupadhyaya
Copy link
Copy Markdown
Contributor

I requested for introducing directories, because I felt like full_node.go and full_client.go + all tests files, will make a bit of a mess sooner than later.

For some context: #661

Both full and light nodes will implement simplified Node interface - which basically allows us to Start a node and create rpc.Client compatible with cosmos-sdk. Client implementation returned by full node will be completely different than the one returned by light node. I don't expect to share a lot of code between light and full nodes & clients.

in this case, why not have this?

node
     - client.go
     - full.go
     - node.go (interface)
     - light.go
     - lightclient.go
     ...

this clearly distinguish full and light implementations and then client refers to full client and for light node client, we can use lightclient?

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 11, 2023

Codecov Report

Merging #681 (3379369) into main (d8679cc) will increase coverage by 0.08%.
The diff coverage is 53.31%.

@@            Coverage Diff             @@
##             main     #681      +/-   ##
==========================================
+ Coverage   54.49%   54.57%   +0.08%     
==========================================
  Files          49       52       +3     
  Lines       10305    10372      +67     
==========================================
+ Hits         5616     5661      +45     
- Misses       3820     3842      +22     
  Partials      869      869              
Impacted Files Coverage Δ
node/light.go 0.00% <0.00%> (ø)
node/light_client.go 0.00% <0.00%> (ø)
node/full.go 60.43% <60.43%> (ø)
rpc/json/service.go 66.43% <78.57%> (+1.43%) ⬆️
node/full_client.go 54.65% <78.94%> (ø)
node/node.go 78.57% <91.66%> (+17.96%) ⬆️
config/config.go 88.88% <100.00%> (+0.88%) ⬆️
state/executor.go 69.90% <0.00%> (+0.72%) ⬆️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@S1nus
Copy link
Copy Markdown
Contributor Author

S1nus commented Jan 11, 2023

I requested for introducing directories, because I felt like full_node.go and full_client.go + all tests files, will make a bit of a mess sooner than later.
For some context: #661
Both full and light nodes will implement simplified Node interface - which basically allows us to Start a node and create rpc.Client compatible with cosmos-sdk. Client implementation returned by full node will be completely different than the one returned by light node. I don't expect to share a lot of code between light and full nodes & clients.

in this case, why not have this?

node
     - client.go
     - full.go
     - node.go (interface)
     - light.go
     - lightclient.go
     ...

this clearly distinguish full and light implementations and then client refers to full client and for light node client, we can use lightclient?

one nice advantage of this organization is that i can make NewFullNode private and accessed through NewNode via the config option.

but i don't have a strong preference, it works either way

@tzdybal
Copy link
Copy Markdown
Contributor

tzdybal commented Jan 11, 2023

You convinced me! Let's use convention proposed by @gupadhyaya .

@tzdybal tzdybal mentioned this pull request Jan 12, 2023
5 tasks
Copy link
Copy Markdown
Contributor

@tzdybal tzdybal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments. This design looks good 👍

Comment thread node/full/client_test.go
Comment thread node/light.go Outdated
Comment thread node/light_client.go Outdated
Comment thread node/light_client.go Outdated
Comment thread node/node.go Outdated
@gupadhyaya
Copy link
Copy Markdown
Contributor

gupadhyaya commented Jan 13, 2023

@S1nus you should also enforce the interface binding by adding var _ Node = &FullNode{} to full.go and var _ Node = &LightNode{} to light.go. similar to how it is done in full_client.go var _ rpcclient.Client = &FullClient{}, also do it for light_client.go to enforce rpcclient.Client interface binding.

Copy link
Copy Markdown
Contributor

@tzdybal tzdybal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some small comments.

Also, this is very good question:

Is there a concern that this won't stop?

I think we should close channel when exiting eventsRoutine in FullClient (using defer).

Comment thread node/light_client.go Outdated
Comment thread node/light_client.go Outdated
@S1nus
Copy link
Copy Markdown
Contributor Author

S1nus commented Jan 15, 2023

I think we should close channel when exiting eventsRoutine in FullClient (using defer).

@tzdybal
what's the purpose of the "resubscribe" part? Should the channel (outc?) be closed on c.Quit or something else?

@tzdybal
Copy link
Copy Markdown
Contributor

tzdybal commented Jan 16, 2023

what's the purpose of the "resubscribe" part?

Tendermint compatibility.

Should the channel (outc?) be closed on c.Quit or something else?

As function has multiple return statemets, it's best to use defer statement on top of function body, like:

func (c *Client) eventsRoutine(sub types.Subscription, subscriber string, q tmpubsub.Query, outc chan<- ctypes.ResultEvent) {
	defer close(outc)
// ...
}

@S1nus
Copy link
Copy Markdown
Contributor Author

S1nus commented Jan 16, 2023

As function has multiple return statemets, it's best to use defer statement on top of function body, like:

fixed?

tzdybal
tzdybal previously approved these changes Jan 17, 2023
Copy link
Copy Markdown
Contributor

@tzdybal tzdybal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just needs a rebase 👍

@tzdybal tzdybal requested a review from nashqueue January 17, 2023 13:13
@nashqueue
Copy link
Copy Markdown
Contributor

@tzdybal @gupadhyaya Going back to the discussion of folder structure/abstraction, as I was not part of that conversation yet. Did we consider the option of having the same architecture as celestia-node? https://github.com/celestiaorg/celestia-node/tree/main/nodebuilder

@S1nus
Copy link
Copy Markdown
Contributor Author

S1nus commented Jan 17, 2023

Did we consider the option of having the same architecture as celestia-node?

Hmm not sure. It is similar, the main difference is RollKit does not use Fx.

@tzdybal tzdybal self-requested a review January 17, 2023 20:00
Copy link
Copy Markdown
Contributor

@tzdybal tzdybal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tzdybal tzdybal changed the title Create server from tendermint rpc client interface Introduce light node & refactor RPC client Jan 18, 2023
@tzdybal tzdybal enabled auto-merge (squash) January 18, 2023 10:17
@tzdybal tzdybal disabled auto-merge January 18, 2023 10:17
@tzdybal tzdybal enabled auto-merge (squash) January 18, 2023 10:18
@tzdybal tzdybal merged commit 008281c into main Jan 19, 2023
@tzdybal tzdybal deleted the connor/wrap-subscribe branch January 19, 2023 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants